package abc.def;

import abc.def.ui.HelperUIThread;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.relics.AbstractRelic;

import java.util.ArrayList;

public class SimpleHelper {
    static private HelperUIThread uiThread = null;
    static public AbstractCard toChangeCard = null;
    static public AbstractRelic.RelicTier nextEliteRelicTier = null;

    static public void switchUI() {
        if (uiThread == null) {
            uiThread = new HelperUIThread();
            uiThread.start();
        } else {
            uiThread.switchDisplay();
        }
    }

    static public void adjustCardReward(ArrayList<AbstractCard> rewardList) {
        if (toChangeCard != null) {
            // check if already exist
            boolean isExist = false;
            for (AbstractCard card : rewardList) {
                if (card.cardID.equals(toChangeCard.cardID)) {
                    isExist = true;
                    break;
                }
            }

            if (!isExist) {
                boolean isChanged = false;
                // check same rarity
                for (AbstractCard card : rewardList) {
                    if (card.rarity == toChangeCard.rarity) {
                        if (card.upgraded) {
                            toChangeCard.upgrade();
                        }
                        rewardList.remove(card);
                        rewardList.add(toChangeCard);
                        isChanged = true;
                        break;
                    }
                }

                if (!isChanged) {
                    AbstractCard removed = rewardList.remove(0);
                    if (removed.upgraded) {
                        toChangeCard.upgrade();
                    }
                    rewardList.add(toChangeCard);
                }
            }

            toChangeCard = null;
        }
    }

    static AbstractRelic.RelicTier adjustEliteRelicTier(AbstractRelic.RelicTier raw) {
        AbstractRelic.RelicTier tier;
        if (nextEliteRelicTier != null) {
            tier = nextEliteRelicTier;
            nextEliteRelicTier = null;
        } else {
            tier = raw;
        }
        return tier;
    }
}
